package com.itheima02.day06;

import java.util.Arrays;

/**
 * @author 刘全
 * @date 2021/7/22
 */
public class KP {
    public static void main(String[] args) {
        int[] arr = {1,9,5,4,8,3};
        get(0,arr.length-1,arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void get(int left, int right, int[] arr) {
        if (right < left) {
            return;
        }
        int left0 = left;
        int right0 = right;
        while (left != right) {
            while (arr[right] >= arr[left0] && right > left) {
                right--;
            }
            while (arr[left] <= arr[left0] && right > left) {
                left++;
            }
            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }
        int temp = arr[left0];
        arr[left0] = arr[left];
        arr[left] = temp;
        get(left0,right-1,arr);
        get(right+1,right0,arr);
    }
}
